/*
 * @Description: 字典数据
 * @Author: huacong
 * @Date: 2020-11-10 21:34:34
 * @LastEditTime: 2020-11-10 21:43:12
 * @LastEditors: huacong
 */
import { mapGetters, mapActions } from 'vuex'

const pending = {}

export default {
  computed: {
    ...mapGetters(['dict'])
  },
  methods: {
    ...mapActions(['getDict']),
    dictFilter (val, feild) {
      if (!this.dict[feild] && !pending.feild) {
        pending.feild = true
        this.getDict({ type: feild }).then(res => {
          const item = res.find(x => x.value === val)
          return item ? item.dicName : ''
        }).finally(() => {
          pending.feild = false
        })
      } else {
        const options = this.dict[feild] || []
        const item = options.find(x => x.value === val)
        return item ? item.dicName : ''
      }
    }
  }
}
